const state = {
  /* Allexam: [
    {
      id: 1,
      name: '单选题',
      topic: [
        {
          id: 1,
          question: 'java基本数据类型',
          selectA: 'int',
          selectB: 'null',
          selectC: 'undefind',
          selectD: 'number'
        },
        {
          id: 2,
          question: 'java整型数据类型',
          selectA: 'int',
          selectB: 'float',
          selectC: 'double',
          selectD: 'object'
        }
      ]
    },
    {
      id: 2,
      name: '多选题',
      topic: [
        {
          id: 1,
          question: 'java基本数据类型',
          selectA: 'int',
          selectB: 'float',
          selectC: 'double',
          selectD: 'object'
        },
        {
          id: 2,
          question: 'java基本数据类型',
          selectA: 'int',
          selectB: 'null',
          selectC: 'undefind',
          selectD: 'number'
        }
      ]
    },
    {
      id: 3,
      name: '判断题',
      topic: [
        { id: 1, question: 'int是整型', selectA: '是', selectB: '不是' },
        { id: 2, question: 'double是整型', selectA: '是', selectB: '不是' }
      ]
    }
  ], */
  Allexam: [
    {
      id: 1,
      name: '单选题',
      path: 'single',
      topic: []
    },
    {
      id: 2,
      name: '多选题',
      path: 'multiple',
      topic: []
    },
    {
      id: 3,
      name: '判断题',
      path: 'judge',
      topic: []
    }
  ],
  examId: '',
  stuId: '',
  examJoinDate: '',
  answerList: [],
  isShow: true
}
const mutations = {
  // 存储答案
  UPLOADANSWER(state, answer) {
    let flag = true
    state.answerList.forEach((item) => {
      if (item.typeId == answer.typeId && item.ids == answer.ids) {
        item.answer = answer.answer
        flag = false
      }
    })
    if (flag) {
      state.answerList.push(answer)
    }
  },
  // 清空答案
  CLEARDATA(state) {
    state.answerList = []
    state.examId = ''
    state.stuId = ''
    state.examJoinDate = ''
  },
  // 存储试卷
  SETEXAM(state, exam) {
    console.log(exam)
    exam.multipleChoiceList.forEach((item, index) => {
      item.ids = index + 1
    })
    state.Allexam[0].topic = exam.multipleChoiceList

    exam.moreMultipleChoiceList.forEach((item, index) => {
      item.ids = index + 1
    })
    state.Allexam[1].topic = exam.moreMultipleChoiceList

    exam.trueOrFalseList.forEach((item, index) => {
      item.ids = index + 1
    })
    state.Allexam[2].topic = exam.trueOrFalseList

    console.log(state.Allexam)
  },
  // 存储考试id SETEXAMID
  SETEXAMID(state, examId) {
    state.examId = examId
  },
  // 存储考试开始时间 SETSTARTTIME
  SETSTARTTIME(state, examJoinDate) {
    state.examJoinDate = examJoinDate
  },
  // 存储考生id
  SETSTUID(state, stuId) {
    state.stuId = stuId
  },
  // 存储
  SETSHOW(state, isShow) {
    state.isShow = isShow
  }
}
const actions = {
  uploadAnswer({ commit }, answer) {
    console.log(answer)
    commit('UPLOADANSWER', answer)
  }
  // async setExam({ commit }, examId) {
  //   commit('SETEXAM', result.data)
  // }
}

const getters = {}

export default {
  state,
  mutations,
  actions,
  getters
}
